package com.mooc.comment.controller;

import com.mooc.comment.common.CommonConstants;
import com.mooc.comment.common.RestResponse;
import com.mooc.comment.model.Comment;
import com.mooc.comment.model.UserMsg;
import com.mooc.comment.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/comment")
public class CommentController {
  
  @Autowired
  private CommentService commentService;
  
  
//  @RequestMapping(value="comment/leaveComment",method={RequestMethod.POST,RequestMethod.GET})
//  public String leaveComment(String content,Long houseId,ModelMap modelMap){
//    User user = UserContext.getUser();
//    Long userId =  user.getId();
//    //commentService.addHouseComment(houseId,content,userId);
//    return "redirect:/house/detail?id=" + houseId;
//  }
//
//  @RequestMapping(value="comment/leaveBlogComment",method={RequestMethod.POST,RequestMethod.GET})
//  public String leaveBlogComment(String content,Integer blogId,ModelMap modelMap,RedirectAttributes redirectAttributes){
//    User user = UserContext.getUser();
//    Long userId =  user.getId();
//    commentService.addBlogComment(blogId,content,userId);
//    return "redirect:/blog/detail?id=" + blogId;
//  }


  @RequestMapping(value="/getHouseComments")
  public RestResponse<List<Comment>> getHouseComments (Long houseId){
     List<Comment> houseComments = commentService.getHouseComments(houseId, CommonConstants.COMMENT_HOUST_SIZE);
     return RestResponse.success(houseComments);
  }

   @RequestMapping("/insertUserMsg")
    public RestResponse   insertUserMsg(@RequestBody UserMsg userMsg){
       commentService.addHouseComment(userMsg.getHouseId(),userMsg.getMsg(),userMsg.getUserId());
       return RestResponse.success();
   }

   @RequestMapping("/addHouseComment")
    public RestResponse addHouseComment(@RequestBody Comment comment){
       commentService.addHouseComment(comment.getHouseId(),comment.getContent(),comment.getUserId());
       return RestResponse.success();
  }



}
